﻿using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;

namespace SharePoint.Orm.TestHelpers {
	public class EnumerableAssert {
		public static void AreEqual<T>(IEnumerable<T> expected, IEnumerable<T> found) {
			IEnumerator<T> expectedEnumerator = expected.GetEnumerator();
			IEnumerator<T> foundEnumerator = found.GetEnumerator();
			while (true) {
				bool expectedMoveNextResult = expectedEnumerator.MoveNext();
				bool foundMoveNextResult = foundEnumerator.MoveNext();
				if (expectedMoveNextResult == false && foundMoveNextResult == false) {
					break;
				}
				if (expectedMoveNextResult != foundMoveNextResult) {
					Assert.AreEqual(expected.Count(), found.Count(), "Number of elements in IEnumerables are different.");
				}
				Assert.AreEqual(expectedEnumerator.Current, foundEnumerator.Current);
			}
		}
	}
}
